﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ISORoleCtrl : MonoBehaviour
{
    private Animator animator;
    private new Rigidbody2D rigidbody2D;
    private SpriteRenderer spriteRenderer;
    private bool isJump;
    private float jumpTimer = 0;
    public float h_speed = 3;
    public float v_speed = 3;
    public float h_Axis;
    public float v_Axis;
    public float dropSpeed = 1;


    // Start is called before the first frame update
    void Start()
    {
        animator = GetComponent<Animator>();
        rigidbody2D = GetComponent<Rigidbody2D>();
        spriteRenderer = transform.Find("RobotBoyRun00").GetComponent<SpriteRenderer>();
    }

    // Update is called once per frame
    void Update()
    {
        h_Axis = Input.GetAxis("Horizontal");
        v_Axis = Input.GetAxis("Vertical");

        rigidbody2D.velocity = new Vector2(h_Axis * h_speed, v_Axis * v_speed);

        if (Input.GetKeyDown(KeyCode.Space) && !isJump)
        {
            isJump = true;
            rigidbody2D.gravityScale = 10;
            rigidbody2D.AddForce(Vector2.up * 1000);
        }
        if (isJump)
        {
            jumpTimer += Time.deltaTime;
            if (jumpTimer >= 1)
            {
                isJump = false;
                rigidbody2D.gravityScale = 0;
                jumpTimer = 0;
            }
        }


        if (h_Axis < 0)
            spriteRenderer.flipX = true;
        else if (h_Axis > 0)
            spriteRenderer.flipX = false;
    }
}
